package com.zhang.crm.controller;

import com.github.pagehelper.PageInfo;
import com.zhang.crm.pojo.TActivity;
import com.zhang.crm.pojo.req.ActivitySearchPageReq;
import com.zhang.crm.result.R;
import com.zhang.crm.service.ActivityService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ActivityController {
    @Resource
    private ActivityService activityService;
    @GetMapping("api/marketActivity")
    public R marketActivity(@RequestParam("current") Integer current){
        PageInfo<TActivity> tActivityPageInfo = activityService.marketActivity(current);
        return R.OK(tActivityPageInfo);
    }

    @GetMapping("api/activityDetails/{id}")
    public R activityDetails(@PathVariable("id") Integer id){
        TActivity activity = activityService.getActivityDetails(id);
        return R.OK(activity);
    }

    @PostMapping("api/addActivity")
    public R addActivity(@RequestBody TActivity tActivity) {
        Boolean b = activityService.addActivity(tActivity);
        return b ? R.OK() : R.FAIL("添加失败");
    }

    @GetMapping("api/activityDetail/{id}")
    public R getActivityDetail(@PathVariable("id")Integer activityId){
        TActivity activityDetails = activityService.getActivityDetails(activityId);
        return R.OK(activityDetails);
    }

    @PutMapping("api/updateActivity")
    public R updateActivity(@RequestBody TActivity tActivity) {
        Boolean b  = activityService.updateActivity(tActivity);
        return b ? R.OK() : R.FAIL("更新失败");
    }

    @DeleteMapping("api/delActivity/{activityId}")
    public R delActivity(@PathVariable("activityId")Integer activityId){
        Boolean b = activityService.delActivityById(activityId);
        return b ? R.OK() : R.FAIL("更新失败");
    }

    @DeleteMapping("api/batchDelActivity")
    public R delActivity(@RequestParam List<Integer> activityIds){
        Boolean b  = activityService.batchDelActivity(activityIds);
        return b ? R.OK() : R.FAIL("更新失败");
    }

    @GetMapping("api/queryPage")
    public R queryPage(ActivitySearchPageReq activitySearchPageReq){
        PageInfo<TActivity> tActivityPageInfo = activityService.queryActivityPageList(activitySearchPageReq);
        return R.OK(tActivityPageInfo);
    }

    @GetMapping("api/loadActivitySelect")
    public R loadActivitySelect(){
        List<TActivity> activityList = activityService.loadActivity();
        return R.OK(activityList);
    }
}
